using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

using XLua;

public static class LuaEnvUtil
{
    public static LuaEnv LuaEnv { get; private set; }

    public static void Init()
    {
        LuaEnv = new LuaEnv();
#if UNITY_EDITOR
        LuaEnv.translator.debugDelegateBridgeRelease = true;
#endif

      //  LuaEnv.AddLoader(ResourceLoader.LoadLua);
        customFunc = null;
    }

    public static void Clear()
    {
    //    LuaEnv?.RmeoveLoader(ResourceLoader.LoadLua);
        LuaEnv?.Dispose();
        LuaEnv = null;
    }

    static float GCInterval = 1;//1 second 
    static float lastGCTime = 0;

    public static void Update()
    {
        if (Time.time - lastGCTime > GCInterval)
        {
            LuaEnv?.Tick();
            lastGCTime = Time.time;
        }
    }

    private static Action<string> customFunc = null;
    public static void RegisterCmd(Action<string> func)
    {
        customFunc += func;
    }

    public static void CallCmd(string cmd)
    {
        customFunc?.Invoke(cmd);
    }
}
